/**
 * User: bruce.kong
 * Date: 14-3-20
 * Time: 下午1:51
 */
var winPop=$(".global_pop");
function screen(){
    var w=document.body.clientWidth;
    return w<1280
}
function resolution(){

    if(screen()){
        document.body.setAttribute("id","s_screen");
    }else{
        document.body.removeAttribute("id");
    }
}
    resolution();
$(window).resize(function(){
    resolution();
});
function popPosition(){
    var popInner=winPop.find(".inner_pop"),popW=popInner.outerWidth(),popH=popInner.outerHeight();
        $('.mask').fadeTo(300,0.5);
        winPop.show().css({"marginTop":-popH/2,"marginLeft":-popW/2});
}
function heightOver(){
    if(screen()){
        winPop.css({"position":"absolute","top":$(document).scrollTop()+40,"marginTop":0});
    }
}
//popPosition();
/*登录*/
$('.login').click(function(){
    $(".global_pop").show().load("login_form.html",function(){
        popPosition();
    });
});
/*登录验证*/
$('.submit_login').live("click",function(check){
    var flag=true,ipts=$('.ipt');
    ipts.each(function(){
        var val= $.trim($(this).val()),msg=$(this).prev("label").text();
        if(val==""){
            errMsg("请输入"+msg,$(this).parent());
            flag=false;
        }
    });


    ipts.focus(function(){
        $(this).next(".error_msg").remove();
    });
    check.preventDefault();
});

var validateRegExp={
    tel: "^[0-9\-()（）]{7,18}$", //电话号码的函数(包括验证国内区号,国际区号,分机号)
    mobile: "^0?(13|15|18|14)[0-9]{9}$", //手机
    email: "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$" //邮件

};
function validateTel(val){return new RegExp(validateRegExp.tel).test(val)}
function validateMobile(val){return new RegExp(validateRegExp.mobile).test(val)}
function validateEmail(val){return new RegExp(validateRegExp.email).test(val)}
/*活动规则*/
$('.rules').click(function(){
    $(".global_pop").show().load("activity_rules.html",function(){
        popPosition();
        $('.jspContainer').height($('.rules_cont').height());
        $('.js_popup_scroll').jScrollPane();
    });
});
/*中奖名单*/
$('.name_list').click(function(){
    $(".global_pop").show().load("prize.html",function(){
        popPosition();
        $('.jspContainer').height($('.prize_cont').height());
        $('.js_popup_scroll').jScrollPane();
    });
});
/*礼品详情*/
$('.gift').click(function(){
    $(".global_pop").show().load("gift_show.html",function(){
        popPosition();
    });
    return false;
});
//popPosition();

    $('.close,.back_edit').live("click",function(){
//        $('.global_pop').animate({"marginTop":-1000},800,function(){
//            $(this).css({"top":50+"%"}).hide();
//        });
        winPop.fadeOut();
        $('.mask').fadeOut();
    });

/*评论文本输入框*/
function focusBlur(obj){
    obj.focus(function(){
        if(this.value==this.defaultValue){
            this.value="";
        }
    }).blur(function(){
            if(this.value==""){
                this.value=this.defaultValue;
            }
        });
}
focusBlur($('.comment'));
/*查看记录*/
$('.view_record').click(function(){
    $('.global_pop').load("view_record.html",function(data){
        popPosition();
        $('.view_slide').imgSlide({
            picBox:".slide_pic",
            btnBox:".btns",
            prevBtn:".prev",
            nextBtn:".next",
            effect:2,
            activeTriggerCls:'c',
            intervalTime:3000
        });
        heightOver();
    })
});
/*立即分享*/
$('.share').click(function(){
    var sinaAccreditUrl="https://api.weibo.com/oauth2/authorize?client_id=2061111585&redirect_uri=http%3A%2F%2Foffice.mediaman.com.cn%2Fdev%2Fother%2Ffnt03_campaign%2Fhome%2Fweibocallback.html&response_type=code";
    var size= {
        "width":629,
        "height":335
    };
    var sinaShare_pop=document.createElement("div");
    var iframe=document.createElement("iframe");
    var closeBtn=document.createElement("div");
    sinaShare_pop.className="sinaShare_pop inner_pop";
    iframe.style.border="none";
    iframe.src=sinaAccreditUrl;
    closeBtn.className="close close_m";
    sinaShare_pop.style.width=size.width+"px";
    sinaShare_pop.style.height=size.height+"px";
    iframe.width=size.width;
    iframe.height=size.height;
    winPop.empty();
    sinaShare_pop.appendChild(iframe);
    winPop[0].appendChild(sinaShare_pop);
    winPop[0].appendChild(closeBtn);
    popPosition();
    return false;
});
function errMsg(msg,obj){
    var msgHtml='<p class="error_msg">'+msg+'</p>';
    obj.find(".error_msg").remove().end().append(msgHtml);

}

